Ext.define('HIT.controller.Report', {
    extend: 'Ext.app.Controller',
    
    models : [ 'ReportTask'],
	stores : [ 'ReportTask','ReportUserDefined'] , 
    views  : ['ReportUserDefinePanel','ReportTaskPanel','ReportCheckPanel','ReportPreviewPanel','ReportInvoicedPanel',
    			'ReportTaxReturns','ReportCustomersBill'],
    onButtonClick: function(button, e, options) {

        if(button.id == 'report-check-yes'){//点击开票核对表的确定
	       	var form=Ext.getCmp('tab-report-invoicecheck');  //确定是当前页面        
	        if (form == undefined) {
	 		   return;
	 		}
	        basicForm = form.getForm();
            if (!basicForm.isValid()) {
               return;
            }
          	var start_time = Ext.ComponentMgr.get("report-check-dateStart").getRawValue() == null ? null:Ext.ComponentMgr.get("report-check-dateStart").getRawValue();
        	var end_time = Ext.ComponentMgr.get("report-check-dateEnd").getRawValue()== null ? null:Ext.ComponentMgr.get("report-check-dateEnd").getRawValue();
        	if(start_time !='' && end_time != '' && start_time !=null && end_time !=null){
				if (end_time < start_time ) {
					Ext.getCmp('report-check-dateEnd').markInvalid(Share.T('结束时间必须大于开始时间'));
					return;
				}
			}
        	var doc_type = Ext.ComponentMgr.get("report-check-docType").getValue()== null ? null:Ext.ComponentMgr.get("report-check-docType").getValue();
        	var doc_type_text = Ext.ComponentMgr.get("report-check-docType").rawValue == null ? null:Ext.ComponentMgr.get("report-check-docType").rawValue;
        	var start_docno = Ext.getCmp('report-check-startdocno').getValue();
        	if (start_docno.search('_M') != -1) {
        		start_docno = start_docno.substring(0, start_docno.indexOf('_M'));
        	}
        	if (start_docno.search('_S') != -1) {
        		start_docno = start_docno.substring(0, start_docno.indexOf('_S'));
        	}
        	var end_docno = Ext.getCmp('report-check-enddocno').getValue();
        	if (end_docno.search('_M') != -1) {
        		end_docno = end_docno.substring(0, end_docno.indexOf('_M'));
        	}
        	if (end_docno.search('_S') != -1) {
        		end_docno = end_docno.substring(0, end_docno.indexOf('_S'));
        	}
        	var start_invoice_no = Ext.getCmp('report-check-startticketno').getValue();
        	var end_invoice_no = Ext.getCmp('report-check-endticketno').getValue();
        	
        	var company_id = Ext.state.Manager.get('Cxjava_companyId');
        	var param = "start_time="+start_time+";end_time="+end_time+";cpn_id="+company_id+";doc_type="+doc_type+";report_name=check_invoice"+";start_docno="+start_docno+";end_docno="+end_docno+";start_invoice_no="+start_invoice_no+";end_invoice_no="+end_invoice_no;
        	var detail = Share.T("时间从")+": "+start_time+","+Share.T("到")+": "+end_time+","+Share.T("票据类型为")+": "+doc_type_text+","+Share.T("起始单据号为")+": "+start_docno+","+Share.T("结束单据号为")+": "+end_docno+","+Share.T("起始发票号为")+": "+start_invoice_no+","+Share.T("结束发票号为")+": "+end_invoice_no;
        	
//        	if(start_time==null || end_time==null || doc_type==null||start_docno.trim().length<1||end_docno.trim().length<1||start_invoice_no.trim().length<1||end_invoice_no.trim().length<1){
//            	Ext.Msg.alert(Share.T("提示"),Share.T("有未填写的选项"));
//            }else{
            	Share.AjaxRequest({
              		 url: ctx + "/generateReport",
                       params: {
                    	   report_param   : param,
              			   report_name    : Share.T("开票核对表"),
              			   detail         : detail
                       },
                       showMsg: false,
                       callback : function(json) {
                  			if(json.resultcode == '0') {
                  				var treepanel = Ext.getCmp('leftpanel');
                               var record = treepanel.getRootNode().findChild("id", 'report-task', true);
                               treepanel.getSelectionModel().select(record, true, false);
                               var grid=Ext.getCmp('tab-report-task');//重载报表任务 
                  				grid.getStore().reload();      				            		
                  			}else if(json.resultcode == '9'){
                  				Share.ShowMessage("E0002","任务写入");
                  			}else{
                  				Ext.Msg.alert(Share.T('错误'),json.resultcode);
                  			}   			
                  		 }  
              	   });
//            }
        }else if(button.id == 'report-preview-yes'){//点击发票预览表
	       	var form=Ext.getCmp('tab-report-invoicepreview');  //确定是当前页面        
	        if (form == undefined) {
	 		   return;
	 		}
	        basicForm = form.getForm();
            if (!basicForm.isValid()) {
               return;
            }
           	var start_time = Ext.ComponentMgr.get("report-preview-dateStart").getRawValue() == null ? null:Ext.ComponentMgr.get("report-preview-dateStart").getRawValue();
        	var end_time = Ext.ComponentMgr.get("report-preview-dateEnd").getRawValue()== null ? null:Ext.ComponentMgr.get("report-preview-dateEnd").getRawValue();
        	if(start_time != '' && end_time != '' && start_time !=null && end_time !=null){
				if (end_time < start_time ) {
					Ext.getCmp('report-preview-dateEnd').markInvalid(Share.T('结束时间必须大于开始时间'));
					return;
				}
			}
        	var doc_type = Ext.ComponentMgr.get("report-preview-docType").getValue()== null ? null:Ext.ComponentMgr.get("report-preview-docType").getValue();
        	var doc_no = Ext.ComponentMgr.get("report-preview-docno").getValue()== null ? null:Ext.ComponentMgr.get("report-preview-docno").getValue();
        	var doc_type_text = Ext.ComponentMgr.get("report-preview-docType").rawValue == null ? null:Ext.ComponentMgr.get("report-preview-docType").rawValue;
        	var company_id = Ext.state.Manager.get('Cxjava_companyId');
        	var param = "doc_no="+doc_no+";start_time="+start_time+";end_time="+end_time+";cpn_id="+company_id+";doc_type="+doc_type+";report_name=invoice_preview";
        	var detail = Share.T("票据号")+": "+doc_no+","+Share.T("时间从")+": "+start_time+","+Share.T("到")+": "+end_time+","+Share.T("票据类型为")+": "+doc_type_text;
        	Share.AjaxRequest({
          		 url: ctx + "/generateReport",
                   params: {
                	   report_param   : param,
          			   report_name    : Share.T("发票预览表"),
          			   detail         : detail
                   },
                   showMsg: false,
                   callback : function(json) {
              			if(json.resultcode == '0') {
              				var treepanel = Ext.getCmp('leftpanel');
                           var record = treepanel.getRootNode().findChild("id", 'report-task', true);
                           treepanel.getSelectionModel().select(record, true, false);
                           var grid=Ext.getCmp('tab-report-task');//重载报表任务 
              				grid.getStore().reload();      				            		
              			}else if(json.resultcode == '9'){
              				Share.ShowMessage("E0002","任务写入");
              			}else{
              				Ext.Msg.alert(Share.T('错误'),json.resultcode);
              			}   			
              		 }  
          	   });
        }else if(button.id == 'report-invoiced-yes'){//点击发票信息表
	       	var form=Ext.getCmp('tab-report-invoiced');  //确定是当前页面        
	        if (form == undefined) {
	 		   return;
	 		}
	        basicForm = form.getForm();
            if (!basicForm.isValid()) {
               return;
            }
           	var start_time = Ext.ComponentMgr.get("report-invoiced-dateStart").getRawValue() == null ? null:Ext.ComponentMgr.get("report-invoiced-dateStart").getRawValue();
        	var end_time = Ext.ComponentMgr.get("report-invoiced-dateEnd").getRawValue()== null ? null:Ext.ComponentMgr.get("report-invoiced-dateEnd").getRawValue();
        	// 开始时间不能大于结束时间
        	if(start_time !='' && end_time != '' && start_time != null && end_time != null){
				if (end_time < start_time ) {
					Ext.getCmp('report-invoiced-dateEnd').markInvalid(Share.T('结束时间必须大于开始时间'));
					return;
				}
			}
        	var doc_type = Ext.ComponentMgr.get("report-invoiced-docType").getValue()== null ? null:Ext.ComponentMgr.get("report-invoiced-docType").getValue();
        	var doc_type_text = Ext.ComponentMgr.get("report-invoiced-docType").rawValue == null ? null:Ext.ComponentMgr.get("report-invoiced-docType").rawValue;
        	var doc_locked = '';
        	var doc_status = '';
        	var doc_name = Ext.ComponentMgr.get("report-invoiced-docType-andlock").rawValue == null ? "NONE":Ext.ComponentMgr.get("report-invoiced-docType-andlock").rawValue;
        	var temp_doc = Ext.ComponentMgr.get("report-invoiced-docType-andlock");
        	var doclock = Ext.ComponentMgr.get("report-invoiced-docType-andlock").lastValue == null ? "":Ext.ComponentMgr.get("report-invoiced-docType-andlock").lastValue;
        	if(doclock == ''){
        		doc_locked = '-1';
        	}else if(Ext.ComponentMgr.get("report-invoiced-docType-andlock").lastValue == 'report_keep'){
        		doc_locked = '1';
        	}else{
        		doc_locked = '0';
        	}
        	if(doclock == 'report_normal_open'){
        		doc_status = '1';
        	}else if(doclock == 'report_normal_disopen'){
        		doc_status = '0';
        	}else if(doclock == 'report_normal_export'){
        		doc_status = '4';
        	}else if(doclock == 'report_normal_check'){
        		doc_status = '3';
        	}else if(doclock == 'report_normal_printing'){
        		doc_status = '2';
        	}else if(doclock == 'report_normal_writeback'){
        		doc_status = '9';
        	}else if(doclock == 'report_normal_sent'){
        		doc_status = '10';
        	}else if(doclock == 'report_normal_informed'){
        		doc_status = '11';
        	}else if(doclock == 'report_keep'){
        		doc_status = '-1';
        	}else if(doclock == ''){
        		doc_status = '-1';
        	}
        	var company_id = Ext.state.Manager.get('Cxjava_companyId');
//        	var company_id = Ext.state.Manager.provider.state.Cxjava_r_company;
        	var param = "start_time="+start_time+";end_time="+end_time+";cpn_id="+company_id+";doc_type="+doc_type+";report_name=invoiced_doc"+";doc_status="+doc_status+";doc_locked="+doc_locked;
        	var detail = Share.T("时间从")+": "+start_time+","+Share.T("到")+": "+end_time+","+Share.T("票据类型为")+": "+doc_type_text+","+Share.T("发票状态为")+": "+doc_name;
        	Share.AjaxRequest({
          		 url: ctx + "/generateReport",
                   params: {
                	   report_param   : param,
          			   report_name    : Share.T("发票信息表"),
          			   detail         : detail
                   },
                   showMsg: false,
                   callback : function(json) {
              			if(json.resultcode == '0') {
              				var treepanel = Ext.getCmp('leftpanel');
                           var record = treepanel.getRootNode().findChild("id", 'report-task', true);
                           treepanel.getSelectionModel().select(record, true, false);
                           var grid=Ext.getCmp('tab-report-task');//重载报表任务 
              				grid.getStore().reload();      				            		
              			}else if(json.resultcode == '9'){
              				Share.ShowMessage("E0002","任务写入");
              			}else{
              				Ext.Msg.alert(Share.T('错误'),json.resultcode);
              			}   			
              		 }  
          	   });
        }else if(button.id == 'report-user-defined-yes'){//点击自定义报表确定按钮
       	 var items = Ext.getCmp('user-defined-field').getLayout().getLayoutItems();
    	 var detail = "";
    	 var param = "report_name="+File_Name+";";
    	  for(var j = 0 ; j<items.length ; j++){
    		  var name = items[j].hiddenName;//parameter
    		  if(name == 'fiscal_year' || name == 'fiscal_period'){
    			  continue;
    		  }
    		  var value = '';
    		  value = items[j].getRawValue() == null ? "-1" : items[j].getRawValue();
    		  value_r = items[j].getValue();
//    		  try{
//    			  if(value.trim().length < 1){
//        			  Ext.MessageBox.alert('错误',items[j].fieldLabel+'为空，无法提交');
//        			  return;
//        		  }
//    		  }catch(e){}
    		  param = param + name + "=";//编写参数字符串，传给后台，给报表
    		  if(name == "fiscal_year"){
    			  detail += Share.T("财年")+": "+value+".";
    			  param += value +';';
    		  }else if(name == "fiscal_period"){
    			  detail += Share.T("期间")+": "+value+".";
    			  param += value +';';
    		  }else if(name == "check"){
    			  detail += Share.T("测试")+": "+value+".";
    			  param += value +';';
    		  }else if(name == "date"){
    			  detail += Share.T("日期")+": "+value+".";
    			  param += value +';';
    		  }else if(name == "doc_type"){
    			  if(value_r == '全部'){
    				  value_r = 'all';
    			  }else if(value_r == '营业税发票'){
    				  value_r = 'BT';
    			  }else if(value_r == '出口发票'){
    				  value_r = 'E_INV';
    			  }else if(value_r == '增值税普通发票'){
    				  value_r = 'N_VAT';
    			  }else if(value_r == '交通运输发票'){
    				  value_r = 'T_INV';
    			  }else if(value_r == '增值税专用发票'){
    				  value_r = 'VAT';
    			  }
    			  detail += Share.T("发票类型")+": "+value_r+".";
    			  param += value_r +';';
    		  }else if(name == "doc_status"){
    			  detail += Share.T("发票状态")+": "+value_r+".";
    			  param += value_r +';';
    		  }else if(items[j].getXType() == 'textfield' || items[j].getXType() == 'combobox' || items[j].getXType() == 'datefield'){
    			  detail += items[j].getFieldLabel()+": "+value+".";
    			  param += value +';';
    		  }else{
    			  detail += items[j].getFieldLabel()+": "+value+".";
    			  param += value +';';
    		  }
    	  }
    	  var cpn_id = Ext.state.Manager.get('Cxjava_companyId'); 
//    	  param = param + "cpn_id="+cpn_id+";user_id="+User_Id+";report_file="+Report_Name;
    	  param = param + "cpn_id="+cpn_id+";report_file="+Report_Name;
//    	  console.log('detail='+detail+'\nreport_param='+param+'\nreport_name='+Report_Name);
    	  Share.AjaxRequest({
     	      	url : ctx + '/generateReport',
     	    	params : {
     	    		detail               : detail//详细说明
     	    	   ,report_param   : param//parameter参数串
     			   ,report_name    : Report_Name//报表名称
     			   //注意：目前陆总那没有写这个对于的服务接口，因此浏览器报错(没有报表名称)
     		   },
     	      callback : function(json) {
     			if(json.resultcode == '0') {
     				var treepanel = Ext.getCmp('leftpanel');
                  var record = treepanel.getRootNode().findChild("id", 'report-task', true);
                  treepanel.getSelectionModel().select(record, true, false);
                  var grid=Ext.getCmp('tab-report-task'); 
     				grid.getStore().reload();      				            		
     			}else if(json.resultcode == '9'){
     				Share.ShowMessage("E0002","任务写入");
     			}else{
     				Ext.Msg.alert(Share.T('错误'),json.resultcode);
     			}   			
     		 }    		
     	  });
        }else if(button.id == 'report-returns-yes'){//纳税申请表
        	var form=Ext.getCmp('tab-report-taxreturns');  //确定是当前页面        
	        if (form == undefined) {
	 		   return;
	 		}
	        basicForm = form.getForm();
            if (!basicForm.isValid()) {
               return;
            }
            var document_sdate = Ext.ComponentMgr.get("document_sdate").getRawValue() == null ? null:Ext.ComponentMgr.get("document_sdate").getRawValue();//单据开始时间
            var document_edate = Ext.ComponentMgr.get("document_edate").getRawValue() == null ? null:Ext.ComponentMgr.get("document_edate").getRawValue();//单据结束时间
            var invoice_sdate = Ext.ComponentMgr.get("invoice_sdate").getRawValue() == null ? null:Ext.ComponentMgr.get("invoice_sdate").getRawValue();//发票开始时间
            var invoice_edate = Ext.ComponentMgr.get("invoice_edate").getRawValue() == null ? null:Ext.ComponentMgr.get("invoice_edate").getRawValue();//发票结束时间
            if ((document_sdate !='' && document_edate != '' && document_sdate != null && document_edate != null) || (invoice_sdate !='' && invoice_edate != '' && invoice_sdate != null && invoice_edate != null)){
            	var showmsg = false;
            	if (invoice_edate < invoice_sdate ) {
					Ext.getCmp('invoice_edate').markInvalid(Share.T('结束时间必须大于开始时间'));
					showmsg = true;
				}
				if (document_edate < document_sdate ) {
					Ext.getCmp('document_edate').markInvalid(Share.T('结束时间必须大于开始时间'));
					showmsg = true;
				}
				if(showmsg){
				    return;
				}
			}
            var company_id = Ext.state.Manager.get('Cxjava_companyId');
            var param = "report_name=tax_returns;"+"cpn_id="+company_id+";document_sdate="+document_sdate+";document_edate="+document_edate+";invoice_sdate="+invoice_sdate+";invoice_edate="+invoice_edate;
            var detail = Share.T("单据时间从")+"："+document_sdate+","+Share.T("到")+"："+document_edate+ ","+Share.T("发票时间从")+"："+invoice_sdate+","+Share.T("到")+":"+invoice_edate;
            Share.AjaxRequest({
              	url: ctx + "/generateReport",
              	params: {
             	   report_param   : param,
           		   report_name    : Share.T("纳税申请表"),
           		   detail         : detail
                },
                showMsg: false,
                callback : function(json) {
          			if(json.resultcode == '0') {
          			   var treepanel = Ext.getCmp('leftpanel');
                       var record = treepanel.getRootNode().findChild("id", 'report-task', true);
                       treepanel.getSelectionModel().select(record, true, false);
                       var grid=Ext.getCmp('tab-report-task');//重载报表任务 
          				grid.getStore().reload();      				            		
          			}else if(json.resultcode == '9'){
          				Share.ShowMessage("E0002","任务写入");
          			}else{
          				Ext.Msg.alert(Share.T('错误'),json.resultcode);
          			}   			
                }
            });
        }else if(button.id == 'report-customerbill-yes'){//客户对账单
        	var form=Ext.getCmp('tab-report-customersbill');  //确定是当前页面        
	        if (form == undefined) {
	 		   return;
	 		}
	        basicForm = form.getForm();
            if (!basicForm.isValid()) {
               return;
            }
            var cust_id = Ext.ComponentMgr.get("cust_id").getRawValue() == null ? null:Ext.ComponentMgr.get("cust_id").getRawValue();//客户代码
            var cust_name = Ext.ComponentMgr.get("cust_name").getRawValue() == null ? null:Ext.ComponentMgr.get("cust_name").getRawValue();//客户名称
            var doc_sno = Ext.ComponentMgr.get("doc_sno").getRawValue() == null ? null:Ext.ComponentMgr.get("doc_sno").getRawValue();//开始单据号
            var doc_eno = Ext.ComponentMgr.get("doc_eno").getRawValue() == null ? null:Ext.ComponentMgr.get("doc_eno").getRawValue();//结束单据号
            var docno_sdate = Ext.ComponentMgr.get("docno_sdate").getRawValue() == null ? null:Ext.ComponentMgr.get("docno_sdate").getRawValue();//单据开始时间
            var docno_edate = Ext.ComponentMgr.get("docno_edate").getRawValue() == null ? null:Ext.ComponentMgr.get("docno_edate").getRawValue();//单据开始时间
            var invoice_sno = Ext.ComponentMgr.get("invoice_sno").getRawValue() == null ? null:Ext.ComponentMgr.get("invoice_sno").getRawValue();//单据开始时间
            var invoice_eno = Ext.ComponentMgr.get("invoice_eno").getRawValue() == null ? null:Ext.ComponentMgr.get("invoice_eno").getRawValue();//单据开始时间
            var invono_sdate = Ext.ComponentMgr.get("invono_sdate").getRawValue() == null ? null:Ext.ComponentMgr.get("invono_sdate").getRawValue();//单据开始时间
            var invono_edate = Ext.ComponentMgr.get("invono_edate").getRawValue() == null ? null:Ext.ComponentMgr.get("invono_edate").getRawValue();//单据开始时间
            if((invono_sdate !='' && invono_edate != '' && invono_sdate != null && invono_edate != null) || (docno_sdate !='' && docno_edate != '' && docno_sdate != null && docno_edate != null)){
            	var showmsg = false;
            	if (docno_edate < docno_sdate ) {
					Ext.getCmp('docno_edate').markInvalid(Share.T('结束时间必须大于开始时间'));
					showmsg = true;
				}
            	if (invono_edate < invono_sdate ) {
					Ext.getCmp('invono_edate').markInvalid(Share.T('结束时间必须大于开始时间'));
					showmsg = true;
				}
            	if(showmsg){
					return;
            	}
			}
            var company_id = Ext.state.Manager.get('Cxjava_companyId');
            var param = "report_name=customers_bill;"+"cpn_id="+company_id+";cust_id="+cust_id+";doc_sno="+doc_sno+";doc_eno="+doc_eno+";docno_sdate="+docno_sdate+";docno_edate="+docno_edate+";invoice_sno="+invoice_sno+";invoice_eno="+invoice_eno+";invono_sdate="+invono_sdate+";invono_edate="+invono_edate;
            var detail = Share.T("客户代码为")+"："+cust_id+","+Share.T("客户名称为")+"："+cust_name+ ","+Share.T("单据号从")+"："+doc_sno+","+Share.T("到")+":"+doc_sno+","+Share.T("单据日期从")+"："+docno_sdate+","+Share.T("到")+":"+docno_edate+","+Share.T("发票号码从")+"："+invoice_sno+","+Share.T("到")+":"+invoice_eno+","+Share.T("发票日期从")+"："+invono_sdate+","+Share.T("到")+":"+invono_edate;
            Share.AjaxRequest({
              	url: ctx + "/generateReport",
              	params: {
             	   report_param   : param,
           		   report_name    : Share.T("客户对账单"),
           		   detail         : detail
                },
                showMsg: false,
                callback : function(json) {
          			if(json.resultcode == '0') {
          			   var treepanel = Ext.getCmp('leftpanel');
                       var record = treepanel.getRootNode().findChild("id", 'report-task', true);
                       treepanel.getSelectionModel().select(record, true, false);
                       var grid=Ext.getCmp('tab-report-task');//重载报表任务 
          				grid.getStore().reload();      				            		
          			}else if(json.resultcode == '9'){
          				Share.ShowMessage("E0002","任务写入");
          			}else{
          				Ext.Msg.alert(Share.T('错误'),json.resultcode);
          			}   			
                }
            });
        }
    },
    
    //自定义报表模板选择   
    onThisTreepanelSelect: function(selModel, record, index, options) {
    	/**************************************************************************************************************
    	 * parameter:传到后台的值是参数名，在控件中以hiddenName的值存在(Ajax做参数名用)									 *
    	 * name:控件的Label(View用)																															 *
    	 * type:控件类型(View用)																																 *
    	 * data:创建控件时的判断条件(Ext.create()辅助用)																							 *
    	 * parameter必须和RPT文件中的参数一致，cpd_id在前台添加到params中，user_id在后台添加到params中。		 *
    	 * JSON文件必须以UTF-8方式编码，浏览器使用UTF-8显示界面																		 *
    	 * report_file：RPT文件名，report_name：JSON文件名																					 *
    	 * *********************************************************************************************************** */
       	var field = Ext.getCmp('user-defined-field');
       	var tool_y = 0;
       	var Sys_Ver = Ext.getCmp('Sys_Ver') == null ? '' : Ext.getCmp('Sys_Ver').getValue(); //Define In view/HeadPanel.js,Use For System
        	field.removeAll();
        	//console.log();
       	if(record.raw.leaf){  
       		var selname = record.raw.text;
       		File_Name = selname;
       		Share.AjaxRequest({
       			url : ctx + '/getUserDefinedContent',
        	    	params : {
        	    		file_name   : selname
        		   },
        		  showMsg  : false,
        	      callback : function(json) {    	    	  
        			if(json.report_file != "") {
        				var field = Ext.getCmp('user-defined-field');
        				Report_Name = json.report_file;
        				for(var i=0;i<json.fields.length;i++){
        					if(json.fields[i].data == "Year" || json.fields[i].data == "PeriodList" || 
        					   json.fields[i].data == "ReportAccountList" || json.fields[i].data == "Currency" || 
        					   json.fields[i].data == "lvl"){
        						continue;
        					}
        	    	      if(json.fields[i].type == "combobox"){//combobox
        	    	    	  if(json.fields[i].data == "doc_type" && Sys_Ver == 'TAX'){//发票类型
        	    	        	 field.add(
             	    	        		new Ext.form.ComboBox({
             	    	        			width: 310,
             	    	        			x:0,
             	    	        			y:tool_y,
             	    	        			fieldLabel:json.fields[i].name,
             	    	        			hiddenName:json.fields[i].parameter,
             	    	        			valueField : 'value',
             								displayField : 'text',
             								store : new Ext.data.JsonStore({
             	 								proxy: { 
             	 									type: 'ajax', 
             	 									url : ctx + '/getInvoiceType2',
             	 									params:{        	 
             	 									},
             	 									reader: { 
             	 										type: 'json', 
             	 										totalProperty: '', 
             	 										root: '' 
             	 									} 
             	 								}, 
             	 							fields:['text','value'], 
             	            	            autoLoad:true,
             	            	            value:0
             					          }),listeners:{
             					        	  beforerender: function(box,eOpts){
             					        		  box.select(Share.T('全部'));//value为"all"
             					        	  }
             					          }
             	    	        		}));
             	    	        	 tool_y += 50;
             	    	         }else if(json.fields[i].data == "doc_status" && Sys_Ver == 'TAX'){//发票状态
             	    	        	 field.add(
                   	    	        		new Ext.form.ComboBox({
                   	    	        			width: 310,
                   	    	        			x:0,
                   	    	        			y:tool_y,
                   	    	        			fieldLabel:json.fields[i].name,
                   	    	        			hiddenName:json.fields[i].parameter,
                   								store : new Ext.data.Store({
                   									fields: ['status_chn','status_num'],
                   									data: [
                   									       {status_chn: '全部',status_num : 'all'},
                   									       {status_chn: '未开票',status_num : '0'},
                   									       {status_chn: '已开票',status_num : '1'},
                   									       {status_chn: '打印中',status_num : '2'},
                   									       {status_chn: '已审核',status_num : '3'},//即：待打印
                   									       {status_chn: '已导出',status_num : '4'},
                   									       {status_chn: '已红冲',status_num : '5'},
                   									       {status_chn: '已关联',status_num : '8'},
                   									       {status_chn: '已回写',status_num : '9'}
                   									       
                   									]
                   								}),
                   								valueField : 'status_num',
                   								displayField : 'status_chn',
                   						        value:'all'
                   	    	        		}));
                   	    	        	 tool_y += 50;
                   	    	         }else if(Sys_Ver == 'TAX'){//其他combobox
                   	    	        	field.add(
                     	    	        		new Ext.form.ComboBox({
                     	    	        			width: 310,
                     	    	        			x:0,
                     	    	        			y:tool_y,
                     	    	        			fieldLabel:json.fields[i].name,
                     	    	        			hiddenName:json.fields[i].parameter,
                     	    	        			valueField : 'value',
                     								displayField : 'text'//,
//                     								store : 这里填写Store
                     	    	        		}));
                     	    	        	 tool_y += 50;
                   	    	         }
        	    	      }else if(json.fields[i].type == "textfield"){//textfield
        	    	    	  field.add(
        	    	  			  new Ext.form.TextField({
        	    	  				 fieldLabel:json.fields[i].name,
        	    	  				 hiddenName:json.fields[i].parameter,
        	    	  				 width:400,
        	    	  				 x:0,
        	    	  				 y:tool_y
        	    	  		        })); 
        	    	    	  tool_y += 30;
        	    	      }else if(json.fields[i].type == "checkbox"){//checkbox
        	    	    	  field.add(
        	    	    		new Ext.form.field.Checkbox({
//        	    	    			id:'report-check-box',
        	    	    			fieldLabel:json.fields[i].name,
        	    	    			hiddenName:json.fields[i].parameter,
        	    	    			width:120,
        	    	    			x:0,
	    					    	y:tool_y
        	    	    		}));
        	    	    	  tool_y += 50;
        	    	      }else if(json.fields[i].type == "datefield"){//datefield
        	    	    	  field.add(
              	    	    		new Ext.form.field.Date({
//              	    	    			id:'report-check-datefield',
              	    	    			fieldLabel:json.fields[i].name,
              	    	    			hiddenName:json.fields[i].parameter,
              	    	    			width:310,
              	    	    			format:'Y-m-d',
              	    	    			x:0,
      	    					    	y:tool_y
              	    	    		}));
              	    	    	  tool_y += 50;
              	    	  }    	    				            		
        				}
        			}else{
        				Share.ShowMessage("E0002","读取文件");
        			}   			
       		 } 
       		});
          }
       },
    init: function(application) {
    	var Report_Name = "";  //JSON里的report_file
    	var File_Name = ""; //JSON文件名
        this.control({
            "button": {
                click: this.onButtonClick
           },
           "#user-defined-tree" :{
               select: this.onThisTreepanelSelect
           }
        });
    }
});
